# -*- coding: utf-8 -*-

'''
author:Cooper
date:2012.5.1
店铺API
taobao.sellercats.list.get 获取前台展示的店铺内卖家自定义商品类目
taobao.shop.get 获取卖家店铺的基本信息
'''

## TODO unittest

from TopAPI.lib import *
import json

class seller_cats():
	api='taobao.sellercats.list.get'
	def __init__(self):
		#self.method='taobao.sellercats.list.get'
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',nick='osa品牌服饰旗舰店'):
		#self.format=format
		#self.nick=nick
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		url=getURL(d)
		return getRes(url)
	def parseSellerCats(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'seller_cats')
	pass

class shop():
	api='taobao.shop.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,format='json',nick='osa品牌服饰旗舰店'):
		#self.format=format
		#self.nick=nick
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='sid,cid,nick,title,desc,\
		bulletin,pic_path,created,modified,shop_score,\
		remain_count,all_count,used_count'
		url=getURL(d)
		return getRes(url)
	def parseShop(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'shop')
	pass

def main():
	cats=seller_cats()
	printJson(cats.parseSellerCats())
	s=shop()
	printJson(s.parseShop())
	pass

if __name__=='__main__':
	main()
	pass
